/******************************************************************************
 * Copyright (C) 2009 Peter ZHOU <peterzhoulei@gmail.com>                     *
 *                                                                            *
 * This program is free software; you can redistribute it and/or              *
 * modify it under the terms of the GNU General Public License as             *
 * published by the Free Software Foundation; either version 2 of             *
 * the License, or (at your option) any later version.                        *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
 ******************************************************************************/

#import "preferenceController.h"

@implementation preferenceController

-(id)init
{
	NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter];
	[nCenter addObserver:self selector:@selector(dictionaryChanged:) name:@"DictionaryChanged" object:nil];
	[nCenter addObserver:self selector:@selector(connectionEnded:) name:@"ConnectionEnded" object:nil];
	self = [super init];
	return self;
}

-(void)connectionEnded:(NSNotification*)notification
{
	[button_connect setEnabled:YES];
}

-(void)dictionaryChanged:(NSNotification*)notification
{
	NSDate* version = [[notification userInfo] objectForKey:@"dicVersion"];
	NSString* versionStr = [[version description] substringToIndex:19];
	[txtVersion setStringValue:[@"字典最后更新： " stringByAppendingString:versionStr]];
}

-(IBAction)connect:(id)sender;
{
	[button_connect setEnabled:NO];
	ddIM_network* newConnection = [[ddIM_network alloc] init];
	[newConnection connectToServer];
}


@end
